<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\common\model\Category as CategoryModel;
use app\common\model\Config;
use fast\Tree;

/**
 * 积分设置
 *
 */
class Points extends Backend
{
    protected $categorylist = [];
    protected $noNeedRight = [''];

    public function _initialize()
    {
        parent::_initialize();
    }

    public function setting()
    {
        $points_setting = Config::where('group', 'basic')->where('name', 'points')->find();

        if ($this->request->isPost()) {
            if (!$points_setting) {
                $points_setting = new Config();
            }
            $points = $this->request->request('row/a');
            $params = [
                'name' => 'points',
                'title' => '积分设置',
                'group' => 'basic',
                'type' => 'array',
                'value' => json_encode($points),
            ];
            $points_setting->save($params);

            $this->success();
        }

        if ($points_setting) {
            $row = json_decode($points_setting['value'], true);
        } else {
            $row = [
                'init' => '',
                'top' => '',
                'status' => '0',
            ];
        }

        $this->assign('row', $row);
        return $this->view->fetch();
    }

}
